Skip to content

Spec: Refactoring: Merge "definitions" and "declarations". #18259

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 1 commit into from
Aug 2, 2023

Conversation

sjrd
Copy link
Member

@sjrd sjrd commented Jul 20, 2023

Previously, abstract members were syntactically separate from concrete members, and referred to "declarations", as opposed to "definitions".

In this commit, all of them become "definitions". There are abstract definitions and concrete definitions. They share their syntactic productions.

This will allow to more easily introduce more kinds of definitions that can be abstract or concrete in deeper productions of the grammar, such as extension methods.

Tentatively assigning to @smarter

@sjrd sjrd requested a review from smarter July 20, 2023 14:48
Copy link
Member

@smarter smarter left a comment

Choose a reason for hiding this comment

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

Otherwise LGTM, nice refactoring!

However, there is a restriction on forward references in blocks:
In a statement sequence ´s_1 ... s_n´ making up a block, if a simple name in ´s_i´ refers to an entity defined by ´s_j´ where ´j \geq i´, then for all ´s_k´ between and including ´s_i´ and ´s_j´,

- ´s_k´ cannot be a variable definition.
- If ´s_k´ is a value definition, it must be lazy.

Moreover, in a block, all definitions must be concrete, and opaque type alias definitions are not allowed.
Copy link
Member

Choose a reason for hiding this comment

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

It's not very useful, but abstract type definitions are allowed in blocks.

@@ -457,7 +452,7 @@ Variance annotations indicate how instances of parameterized types vary with res
A ‘+’ variance indicates a covariant dependency, a ‘-’ variance indicates a contravariant dependency, and a missing variance indication indicates an invariant dependency.

A variance annotation constrains the way the annotated type variable may appear in the type or class which binds the type parameter.
In a type definition `type ´T´[´\mathit{tps}\,´] = ´S´`, or a type declaration `type ´T´[´\mathit{tps}\,´] >: ´L´ <: ´U´` type parameters labeled ‘+’ must only appear in covariant position whereas type parameters labeled ‘-’ must only appear in contravariant position.
In a type definition `type ´T´[´\mathit{tps}\,´] = ´S´`, `type ´T´[´\mathit{tps}\,´] >: ´L´ <: ´U´` or `type ´T´[´\mathit{tps}\,´] >: ´L´ <: ´U´ = ´S´`, type parameters labeled ‘+’ must only appear in covariant position whereas type parameters labeled ‘-’ must only appear in contravariant position.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
In a type definition `type ´T´[´\mathit{tps}\,´] = ´S´`, `type ´T´[´\mathit{tps}\,´] >: ´L´ <: ´U´` or `type ´T´[´\mathit{tps}\,´] >: ´L´ <: ´U´ = ´S´`, type parameters labeled ‘+’ must only appear in covariant position whereas type parameters labeled ‘-’ must only appear in contravariant position.
In a type definition `type ´T´[´\mathit{tps}\,´] = ´S´`, `type ´T´[´\mathit{tps}\,´] >: ´L´ <: ´U´` or `opaque type ´T´[´\mathit{tps}\,´] >: ´L´ <: ´U´ = ´S´`, type parameters labeled ‘+’ must only appear in covariant position whereas type parameters labeled ‘-’ must only appear in contravariant position.

A parameter signature consists of an optional type parameter clause `[´\mathit{tps}\,´]`, followed by zero or more value parameter clauses `(´\mathit{ps}_1´)...(´\mathit{ps}_n´)`.
Such a declaration or definition introduces a value with a (possibly polymorphic) method type whose parameter types and result type are as given.
Such a definition introduces a method with a type (if there is no type or term parameter clause) or methodic type whose parameter types and result type are as given (otherwise).
Copy link
Member

Choose a reason for hiding this comment

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

This sentence is hard to parse, are we distinguishing "method with a type" versus "method with a methodic type"? Could the former be called "method with a proper type" to avoid confusion?

Copy link
Member Author

Choose a reason for hiding this comment

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

Is it better now?

@@ -580,11 +573,11 @@ A unary operator is a method named `"unary_´op´"` where ´op´ is one of `+`,

### Default Arguments

Each value parameter declaration may optionally define a default argument.
Each formal value parameter may optionally define a default argument.
Copy link
Member

Choose a reason for hiding this comment

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

It looks like the spec uses both "formal parameter" and "parameter" interchangeably, either seems fine (as long as arguments are called arguments and not parameters), but it'd be preferable to stick to one terminology (e.g. just below "for every parameter").

@smarter smarter assigned sjrd and unassigned smarter Aug 2, 2023
Previously, abstract members were syntactically separate from
concrete members, and referred to "declarations", as opposed to
"definitions".

In this commit, all of them become "definitions". There are
abstract definitions and concrete definitions. They share their
syntactic productions.

This will allow to more easily introduce more kinds of definitions
that can be abstract or concrete in deeper productions of the
grammar, such as extension methods.
@sjrd sjrd force-pushed the spec-merge-definitions-and-declarations branch from 445c8e2 to 86d06b4 Compare August 2, 2023 14:03
@sjrd sjrd enabled auto-merge August 2, 2023 14:29
@sjrd sjrd merged commit ec64ae0 into scala:main Aug 2, 2023
Kordyjan added a commit that referenced this pull request Dec 8, 2023
… to LTS (#19142)

Backports #18259 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
@Kordyjan Kordyjan added this to the 3.3.2 milestone Dec 14, 2023
@sjrd sjrd deleted the spec-merge-definitions-and-declarations branch January 10, 2024 08:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants