Skip to content

Spec is unclear on function body identifier context #1574

Closed

Description

@tomstuart

As far as I can tell, the text format spec doesn’t explain how a module’s initial identifier context should reach the body of a function definition, which I assume it must somehow.

The func production synthesises an identifier context $I''$ for the function body by composing $I'$ (synthesised by typeuse) with a context containing the function definition’s local variable identifiers, so the inherited attribute $I$ containing the module’s initial context is not directly used. But the typeuse production itself also discards $I$: the $I'$ in its synthesised attribute contains only the parameter identifiers. The only syntactic occurrence of $I$ in these productions is when typeuse looks up the definition of the function’s type.

It’s therefore unclear how the remaining contents of $I$ are made available to the function body. The prose accompanying the typeuse production does mention “the updated identifier context including possible parameter identifiers” (emphasis mine), which perhaps implies that $I'$ is intended to be formed by extending the inherited attribute $I$ rather than discarding it (e.g. $I' = I \oplus \lbrace \mathsf{locals}~(\epsilon)^n \rbrace$ etc), but that’s just a guess.

How is this intended to work? Can the spec be updated to clarify?

Activity

  1. rossberg commented on Jan 19, 2023

    @rossberg
    Member

    Yes, thanks for pointing out! There is a composition missing. Please see #1578 for a fix.

  2. tomstuart commented on Jan 19, 2023

    @tomstuart
    ContributorAuthor

    Thank you! #1578 does a good job of clarifying that (contrary to my guess above) the typeuse production is supposed to include only the parameter identifiers in $I'$, with these and the local variable identifiers getting composed with the initial context $I$ in the func production to form the local context $I''$ for the function body.

  3. rossberg commented on Jan 19, 2023

    @rossberg
    Member

    Both would work, of course, and I believe your guess was indeed my original intention. But I just figured that the patch in #1578 avoids duplicating the composition.

  4. tomstuart commented on Jan 19, 2023

    @tomstuart
    ContributorAuthor

    Yeah, it’s neater this way — typeuse is self-contained and only reports any parameter identifiers, and then func is responsible for assembling the pieces. I like it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions