Skip to content

Conversation

pschuh
Copy link
Contributor

@pschuh pschuh commented Mar 28, 2019

For reference, all other literal types except dictionaries and string
interpolation have been converted over to this form.

@slavapestov
Copy link
Contributor

Hey, I’m sorry I missed this! Do you mind rebasing to fix the merge conflict?

@pschuh
Copy link
Contributor Author

pschuh commented Jun 3, 2019

@swift-ci Please test

@swift-ci
Copy link
Contributor

swift-ci commented Jun 3, 2019

Build failed
Swift Test Linux Platform
Git Sha - f94d07d6932bad48eb6fbf5eafe200b9373ebcb9

@swift-ci
Copy link
Contributor

swift-ci commented Jun 3, 2019

Build failed
Swift Test OS X Platform
Git Sha - f94d07d6932bad48eb6fbf5eafe200b9373ebcb9

@pschuh
Copy link
Contributor Author

pschuh commented Jun 3, 2019

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Jun 3, 2019

Build failed
Swift Test OS X Platform
Git Sha - 3854bf2e65563431fb40a5576c500e8b97b3a1b5

@swift-ci
Copy link
Contributor

swift-ci commented Jun 3, 2019

Build failed
Swift Test Linux Platform
Git Sha - 3854bf2e65563431fb40a5576c500e8b97b3a1b5

…emanticExpr.

For reference, all other literal types except dictionaries and string
interpolation have been converted over to this form.
@pschuh
Copy link
Contributor Author

pschuh commented Jun 3, 2019

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Jun 3, 2019

Build failed
Swift Test OS X Platform
Git Sha - 3854bf2e65563431fb40a5576c500e8b97b3a1b5

@swift-ci
Copy link
Contributor

swift-ci commented Jun 3, 2019

Build failed
Swift Test Linux Platform
Git Sha - 3854bf2e65563431fb40a5576c500e8b97b3a1b5

@pschuh
Copy link
Contributor Author

pschuh commented Jun 3, 2019

@slavapestov

I'm able to reproduce the mac failure (or a failure that looks similar), It is this pattern of protocols and classes:

class Color { required init() {} }

protocol Silly {
  init()
  init(_colorLiteralRed red: Float, green: Float, blue: Float, alpha: Float)
}

extension Silly {
  init(_colorLiteralRed red: Float, green: Float, blue: Float, alpha: Float) {
    self.init()
  }
}

extension Color : Silly, _ExpressibleByColorLiteral {}

func makeColorLiteral() -> Color {
  return #colorLiteral(red: 1.358, green: -0.074, blue: -0.012, alpha: 1.0)
}

print(makeColorLiteral())

This results in the following substitution map: (note the τ_0_0 that shows up out of nowhere and the inherited_conformance)

(substitution_map generic_signature=<Self where Self : Silly>
  (substitution Self -> τ_0_0)
  (conformance type=Self
    (inherited_conformance type=τ_0_0 protocol=Silly
      (normal_conformance type=Color protocol=Silly
        (value req=init() witness=test.(file).Color.init()@test.swift:3:12)
        (value req=init(_colorLiteralRed:green:blue:alpha:) witness=test.(file).Silly extension.init(_colorLiteralRed:green:blue:alpha:)@test.swift:12:3)))))

What really baffles me is that if I swap everything out for ArrayLiteral (which uses identical conformance lookup logic), I get the following substitution map: (which has no extra type parameter)

(substitution_map generic_signature=<Self where Self : Silly>
  (substitution Self -> Color)
  (conformance type=Self
    (normal_conformance type=Color protocol=Silly
      (value req=init() witness=test2.(file).Color.init()@test2.swift:3:12)
      (value req=init(arrayLiteral:) witness=test2.(file).Silly extension.init(arrayLiteral:)@test2.swift:12:3))))

This all happens in the CSApply.cpp code and happens in the conformance.getWitnessByName(type, name); snippet.

(normal_conformance type=Color protocol=_ExpressibleByColorLiteral
  (value req=init(_colorLiteralRed:green:blue:alpha:) witness=test.(file).Silly extension.init(_colorLiteralRed:green:blue:alpha:)@test.swift:12:3))

@slavapestov
Copy link
Contributor

I don't think we should be building an InheritedProtocolConformance for a class-constrained type parameter like that. Do you want me to take a look?

@pschuh
Copy link
Contributor Author

pschuh commented Jun 10, 2019

Yes, please.

@slavapestov
Copy link
Contributor

The problem is that the substitutions stored inside the witness itself are meant for SILGen to use when emitting a witness thunk. They're not always in terms of the generic signature of the type in the conformance. In fact this only happens when the 'synthetic environment' is sufficiently simple, but the two non-trivial cases are when the requirement is generic, or when the witness is in a protocol extension and the conforming type is a class. I think this will break for any literal protocol where a witness is in a protocol extension and the literal type is a class. However, it worked for arrays because of another workaround elsewhere.

I have a tentative fix in #25350.

@pschuh pschuh closed this Jun 13, 2019
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