Skip to content
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

Replace BasicType by PrimaryType #3917

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

Bolpat
Copy link
Contributor

@Bolpat Bolpat commented Sep 26, 2024

Essentially, this change renames BasicType to PrimaryType and gives BasicType a new meaning.

The entity BasicType and the term basic type will be used for the non-recursive rules in the type grammar. The recursive rules are TypeCtor(Type) and __vector(Type). Those would constitute elaborate primary types (with elaborate = non-basic). The non-recursive rules are e.g. fundamental types, identifiers, mixin types, typeof types, etc., stuff that doesn’t immediately require parsing a Type again.

This is in prospect of the Primary Type Syntax DIP which, if accepted, will make PrimaryType truly be the type equivalent to PrimaryExpression in the expression syntax. Note that any DIP that adds tuples to the grammar based on parentheses, e.g. one that makes (int, int) a type, will profit from this change because such a type would be an elaborate primary type, and parts of the grammar spec (or forum discussions) can then easily distinguish primary and basic types in places where parsing ambiguity must be avoided.

In particular, this change allows the grammar spec to require a non-trivial type construct that is not a qualified type in code. This makes sense in places where the qualifier would be ignored if given, e.g. base class lists and, possibly in the future, the argument of __vector.

I’m not that deep into the SIMD types, so I left it alone, but as far as I understand, it could be constrained syntactically so that providing an ill-formed vector type fails fast. Essentially, a vector type would probably be __vector(BasicType TypeSuffixesopt) where the TypeSuffixes are optional because if BasicType is something other than a FundamentalType, it could already be a static array.

The parser changes required by this change are implemented in this PR.

Changes

Most changes are BasicType to PrimaryType.

class.dd

Remove the unnecessary SuperClassOrInterface and Interfaces / Interface grammar entities, those are all BasicType now. A base class should not be spelled out in code as e.g. const(Object) as it’s equivalent to Object. if a mixin or ´typeof` resolves to a qualified type, the qualifiers are still ignored. This is about parsing only.

declaration.dd

Rephrased a paragraph mentioning “basic type” with no actual connection to BasicType.

expression.dd

Also renames BasicTypeWithSuffixes to SuffixedPrimaryType

simd.dd

Because I inlined the Vector grammar entity, some rephrasing was needed.

template.dd

For TemplateValueParameter, I changed BasicType to Type because this is what the compiler implements and there’s no good reason to change the compiler. This change would also encompass the Primary Type Syntax DIP and (likely) any tuple DIP.

type.dd

Rephrased a paragraph mentioning “basic type” with no actual connection to BasicType.

@dlang-bot
Copy link
Contributor

Thanks for your pull request and interest in making D better, @Bolpat! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

@Bolpat Bolpat changed the title Replace BasicType by PrimaryType mostly Replace BasicType by PrimaryType Sep 26, 2024
@thewilsonator
Copy link
Contributor

Has that DIP been accepted? DMD uses BaiscType all over the place to what you now refer to as a primary type.

@@ -1644,7 +1601,7 @@ $(GNAME PostfixExpression):
$(GSELF PostfixExpression) $(D ++)
$(GSELF PostfixExpression) $(D --)
$(GSELF PostfixExpression) $(D $(LPAREN)) $(GLINK NamedArgumentList)$(OPT) $(D $(RPAREN))
$(GLINK2 type, TypeCtors)$(OPT) $(GLINK2 type, BasicType) $(D $(LPAREN)) $(GLINK NamedArgumentList)$(OPT) $(D $(RPAREN))
Copy link
Contributor

Choose a reason for hiding this comment

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

Why remove $(GLINK2 type, TypeCtors)$(OPT)? The following compiles with DMD:

auto x = const int(5);

$(GLINK Interface) $(D ,) $(GSELF Interfaces)

$(GNAME Interface):
$(GLINK2 type, BasicType)
Copy link
Contributor

Choose a reason for hiding this comment

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

SuperClassOrInterface and Interfaces are still referenced by AnonBaseClassList and BaseInterfaceList.

$(GNAME PrimaryType):
$(GLINK BasicType)
$(D __vector) $(D $(LPAREN)) $(GLINK Type) $(D $(RPAREN))
$(GLINK TypeCtor)$(OPT) $(D $(LPAREN)) $(GLINK Type) $(D $(RPAREN))
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be without $(OPT) for now? This change is from your DIP, but I thought this pull request is only a preparation.

@Bolpat
Copy link
Contributor Author

Bolpat commented Sep 26, 2024

There have been some unintentional changes slipping through. I don’t know how or why… I’ll look into this tomorrow.

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.

4 participants