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

fix(compiler): Use strict to check types availability [LNG-334] #1071

Merged
merged 10 commits into from
Feb 12, 2024

Conversation

DieMyst
Copy link
Member

@DieMyst DieMyst commented Feb 7, 2024

Description

Use strict to prevent registering types when there is types with the same name imported from another file.
Also, fix token locations for services, abilities and structures.

fixes LNG-334
fixes LNG-335
fixes LNG-336
fixes LNG-299
fixes LNG-300

Checklist

  • Corresponding issue has been created and linked in PR title.
  • Proposed changes are covered by tests.
  • Documentation has been updated to reflect the changes (if applicable).
  • I have self-reviewed my code and ensured its quality.
  • I have added/updated necessary comments to aid understanding.

Reviewer Checklist

  • Tests have been reviewed and are sufficient to validate the changes.
  • Documentation has been reviewed and is up to date.
  • Any questions or concerns have been addressed.

Copy link

linear bot commented Feb 7, 2024

@DieMyst DieMyst added the e2e Run e2e workflow label Feb 7, 2024
@DieMyst DieMyst changed the title bug(compiler): Use strict to check types availability fix(compiler): Use strict to check types availability Feb 7, 2024
@DieMyst DieMyst changed the title fix(compiler): Use strict to check types availability fix(compiler): Use strict to check types availability [LNG-334] Feb 8, 2024
@DieMyst DieMyst marked this pull request as ready for review February 9, 2024 06:35
Copy link

linear bot commented Feb 9, 2024

@@ -14,7 +14,7 @@ import cats.syntax.validated.*

final case class TypeResolution[S[_], +T](
`type`: T,
definitions: List[(Token[S], NamedTypeToken[S])]
definitions: List[(Token[S], String)]
Copy link
Contributor

@InversionSpaces InversionSpaces Feb 9, 2024

Choose a reason for hiding this comment

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

After change, those are not definitions, but occurrences rather.
I am scared by amount of (Token[S], String) in the code. Maybe create a class for that already?

@@ -99,7 +99,7 @@ class ValuesAlgebra[S[_], Alg[_]: Monad](using
case None =>
(for {
t <- OptionT(
T.getType(name.value)
T.getType(name.value, name)
Copy link
Contributor

Choose a reason for hiding this comment

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

We could accept NamedTypeToken[S] in getType. Name[S] have method asTypeToken

Copy link
Contributor

Choose a reason for hiding this comment

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

Also getType does exactly the same as resolveType, except that resolveType might report an error. In NamesAlgebra in similar situation we added a boolean flag to control error reporting. Maybe do the same here and remove getType method?


override def resolveType(token: TypeToken[S]): State[X, Option[Type]] =
getState.map(TypeResolution.resolveTypeToken(token)).flatMap {
case Valid(TypeResolution(typ, tokens)) =>
val tokensLocs = tokens.map { case (t, n) => n.value -> t }
val tokensLocs = tokens.map { case (t, n) => n -> t }
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe return them in this order inside TypeResolution?

@@ -720,7 +722,7 @@ class TypesInterpreter[S[_], X](using
)(
ifNotDefined: => State[X, A]
): State[X, A] = getState
.map(_.definitions.get(name))
.map(_.strict.get(name))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
.map(_.strict.get(name))
.map(_.getType(name))

@@ -180,8 +182,7 @@ class TypesInterpreter[S[_], X](using
)

override def defineAlias(name: NamedTypeToken[S], target: Type): State[X, Boolean] =
getState.map(_.definitions.get(name.value)).flatMap {
case Some(n) if n == name => State.pure(false)
getState.map(_.strict.get(name.value)).flatMap {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
getState.map(_.strict.get(name.value)).flatMap {
getState.map(_.getType(name.value)).flatMap {

override def getType(name: String): State[X, Option[Type]] =
getState.map(st => st.strict.get(name))
override def getType(name: String, token: Token[S]): State[X, Option[Type]] =
OptionT(getState.map(st => st.strict.get(name)))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
OptionT(getState.map(st => st.strict.get(name)))
OptionT(getState.map(st => st.getType(name)))

…cationsInterpreter.scala

Co-authored-by: InversionSpaces <[email protected]>
@DieMyst DieMyst enabled auto-merge (squash) February 12, 2024 05:42
@DieMyst DieMyst merged commit 17fb77c into main Feb 12, 2024
10 checks passed
@DieMyst DieMyst deleted the LNG-334-types-context branch February 12, 2024 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
e2e Run e2e workflow
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants