Skip to content

SR-6717 Builtin types are always be printed with Builtin prefix #27732

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
Oct 21, 2019

Conversation

JGiola
Copy link
Contributor

@JGiola JGiola commented Oct 16, 2019

ASTPrinter now ignore the Options.FullyQualifiedTypesIfAmbiguous value if the containing module is the builtin one.

As stated in the bug report, I've implemented the test in the description to validate the fix but if someone has a more self-contained example I will swap it in no time.

Resolves SR-6717.

Copy link
Contributor

@jrose-apple jrose-apple left a comment

Choose a reason for hiding this comment

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

Thanks for picking this up! I have a few comments but I'm glad the solution was this straightforward.

@@ -3529,6 +3526,9 @@ class TypePrinter : public TypeVisitor<TypePrinter> {

ModuleDecl *M = D->getDeclContext()->getParentModule();

if (!Options.FullyQualifiedTypesIfAmbiguous && !M->isBuiltinModule())
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is equivalent today, but we could go even further by always returning true if M->isBuiltinModule() and then testing Options.FullyQualifiedTypesIfAmbiguous after that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No problem, I've separated the two checks

// RUN: %target-typecheck-verify-swift

let x = 0
_ = x._value == x // expected-error {{referencing operator function '==' on 'BinaryInteger' requires that 'Builtin.Int64' conform to 'BinaryInteger'}}
Copy link
Contributor

Choose a reason for hiding this comment

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

So, the comment about tests in the Jira was about not relying on the implementation details of Int (the _value property). Instead, you can make some other type in this file that uses Builtin.Int64 (or whatever) as a stored property by adding -parse-stdlib to the test invocation. (You'll then need to import Swift to still get access to the normal standard library.)

Copy link
Contributor Author

@JGiola JGiola Oct 16, 2019

Choose a reason for hiding this comment

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

Something like this one that I've pushed now?

@jrose-apple
Copy link
Contributor

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 88ccecf48afe673954cf22ebc6b9628c09ecd25a

@jrose-apple
Copy link
Contributor

17:00:43 
swift/test/type/builtin_types.swift:5:29: error: unexpected error produced: cannot convert value of type 'Int' to specified type 'Builtin.Int64'
17:00:43 let builtin:Builtin.Int64 = 0
17:00:43                             ^

Ah, that makes sense: a builtin type doesn't have any of the initialization logic that a normal type does. You can sidestep this problem by using a function that takes a Builtin.Int64 instead.

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 88ccecf48afe673954cf22ebc6b9628c09ecd25a

@JGiola
Copy link
Contributor Author

JGiola commented Oct 18, 2019

Ok I’m lost, I don’t know how to use all the builtin stuff and I can’t figure how to write the test :(

@jrose-apple
Copy link
Contributor

There's no real documentation on it, so that's not surprising! I was thinking of something like this:

import Swift

func test(_ builtin: Builtin.Int64) {
  let x = 0
  _ = x == builtin // expected-error {{operator function '==' requires that 'Builtin.Int64' conform to 'BinaryInteger'}}
}

@JGiola
Copy link
Contributor Author

JGiola commented Oct 18, 2019

Oh yes, I was rethinking on it during work, and it struck me that I was only suppose to trigger an error not generate a valid Builtin value to use in the current check. Sorry for the trouble

@JGiola JGiola force-pushed the SR-6717 branch 2 times, most recently from 84f7d7e to 396254a Compare October 18, 2019 18:24
@JGiola
Copy link
Contributor Author

JGiola commented Oct 18, 2019

Ok I’ve updated the test

@jrose-apple
Copy link
Contributor

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 88ccecf48afe673954cf22ebc6b9628c09ecd25a

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 88ccecf48afe673954cf22ebc6b9628c09ecd25a

@jrose-apple
Copy link
Contributor

Looks like it worked! …but other tests need to be updated for this change as well. Mind getting those too?

@JGiola
Copy link
Contributor Author

JGiola commented Oct 18, 2019

I’m on it

@jrose-apple
Copy link
Contributor

Ah…what about the other failures? https://ci.swift.org/job/swift-PR-Linux/16520/consoleFull

You should be able to run the tests locally as well, either by using build-script or one of the lit.py invocations in docs/Testing.md.

@JGiola
Copy link
Contributor Author

JGiola commented Oct 18, 2019

Ops, my bad. I haven’t seen the SILOptimizer one in the log. I’ve fixed them, and I will running the full suite tonight for catching other failures if there are any.

ASTPrinter now ignore the Options.FullyQualifiedTypesIfAmbiguous
value if the containing module is the builtin one.
@JGiola
Copy link
Contributor Author

JGiola commented Oct 19, 2019

Ok now, at least on a mac, all tests pass!

@theblixguy
Copy link
Collaborator

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 396254ac2322450fcaa7b9b00a451f48208d15e4

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 396254ac2322450fcaa7b9b00a451f48208d15e4

@jrose-apple jrose-apple merged commit 91664f2 into swiftlang:master Oct 21, 2019
@jrose-apple
Copy link
Contributor

Thanks, @JGiola!

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