8000 Expose the names of generated record constructors (reopen #6975) by plt-amy · Pull Request #7510 · agda/agda · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Expose the names of generated record constructors (reopen #6975) #7510

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 26, 2024

Conversation

plt-amy
Copy link
Member
@plt-amy plt-amy commented Sep 25, 2024

The keyword constructor can appear as the last token in a qualified name, as long as it's the only name part. So Foo.constructor, Foo.Bar.constructor are both valid, but constructor and Foo.constructor.bar are still syntax errors.

The Foo.constructor syntax is actual syntax. It looks like a name, but there's no constructor name in the module Foo. That would be incorrect anyway, since the record module is parametrized by a value of the record type, but the constructor isn't; see #4189.

To resolve Foo.constructor, we look up Foo as an unambiguous record name, and then resolve to the actual name of the constructor, which is still kept internal. This means that Foo.constructor is in scope as long as Foo is, so this doesn't reintroduce #282.

I quickly threw the implementation back together on top of master because it would be easier than rebasing or merging. Also: as discussed in the meeting on 09-25, the Foo.constructor name is now always in scope (whenever Foo) is, regardless of whether the constructor is named.

@plt-amy plt-amy added the record constructors Issues involving record constructors. label Sep 25, 2024
@plt-amy plt-amy requested a review from andreasabel September 25, 2024 16:29
Copy link
Member
@andreasabel andreasabel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

@plt-amy plt-amy force-pushed the aliao/expose-record-constructors branch from 6a1fabf to 428f660 Compare September 26, 2024 13:54
@plt-amy plt-amy force-pushed the aliao/expose-record-constructors branch from 428f660 to 8023232 Compare September 26, 2024 14:47
@andreasabel andreasabel added the pr: squash-me This PR needs squashing label Sep 26, 2024
@plt-amy plt-amy merged commit 3ff01ab into master Sep 26, 2024
29 checks passed
@plt-amy plt-amy deleted the aliao/expose-record-constructors branch September 26, 2024 17:31
andreasabel added a commit that referenced this pull request Sep 26, 2024
…ecords

Since ConstructorName can no longer take an empty set (commit
ac2888a), we need to store the inductivity of a record in the new
scopeRecords component.
@andreasabel
Copy link
Member
8000

@plt-amy Now that I am working with the code of this PR due to #7513, I wonder whether the new scopeRecords component is needed in ScopeInfo. Couldn't we rather just add the constructor name (and inductivity, see #7513) to the IsRecordModule constructor?

data ScopeInfo = ScopeInfo
{ _scopeCurrent :: A.ModuleName
, _scopeModules :: Map A.ModuleName Scope

data Scope = Scope
{ scopeName :: A.ModuleName
, scopeParents :: [A.ModuleName]
, scopeNameSpaces :: ScopeNameSpaces
, scopeImports :: Map C.QName A.ModuleName
, scopeDatatypeModule :: Maybe DataOrRecordModule
}

data DataOrRecordModule
= IsDataModule
| IsRecordModule

m0 <- getCurrentModule
let m = A.qualifyM m0 $ mnameFromList1 $ singleton $ List1.last $ qnameToList x'
printScope "rec" 25 "before record"
createModule (Just IsRecordModule) m

The respective setter and getter (that currently use scopeRecords) should be still definable.


-- | Record (ha) that a given record has the specified constructor name.
setRecordConstructor :: A.QName -> A.QName -> ScopeM ()
setRecordConstructor recr con = modifyScope_ $ over scopeRecords $ Map.insert recr con
Copy link
Member
@andreasabel andreasabel Sep 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Morally, recr should be an A.ModuleName, shouldn't it?
(Or at least it could, since each record type doubles as record module.)

fredins pushed a commit to fredins/agda that referenced this pull request Nov 24, 2024
* Record.constructor syntax: basic impl

* Record.constructor syntax: add test cases

* Record.constructor syntax: changelog & docs

* Record.constructor syntax: updated tests

* Record.constructor: Simplify errors and parsing
fredins pushed a commit to fredins/agda that referenced this pull request Nov 24, 2024
…opeRecords

Since ConstructorName can no longer take an empty set (commit
ac2888a), we need to store the inductivity of a record in the new
scopeRecords component.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: squash-me This PR needs squashing record constructors Issues involving record constructors.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0