Skip to content

[SE-0155][WIP] Normalize Enum Case Representation #12397

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

Closed

Conversation

CodaFi
Copy link
Contributor

@CodaFi CodaFi commented Oct 12, 2017

⚠️ DO NOT MERGE ⚠️

SE-0155 Requirements:

  • Ban case Foo(), rewrite to case Foo(Void)
  • Labels in associated value clauses are part of the case name
  • Case name overloading on distinct full names
  • Default arguments in associated value clauses
  • Consistent pattern matching behavior (see below)

A number of cleanups fell out of this patch:

  • EnumElementDecls owning a parameter list simplifies both serialization and AST printing
  • SourceKit now reports EnumElementDecls as owning a parameter list instead of a tuple
  • Function types in enum cases are implicitly marked @escaping and actually participate in semantic checks

Some open questions:

// indirect case elet(locals: [(String, Expr)], body: Expr)
// }
//
// Expr.elet(locals: body:)([], someExpr)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gottesmm Any thoughts here?

Copy link
Contributor

Choose a reason for hiding this comment

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

What is "an uncurried EnumInst payload sans argument labels"?

Copy link
Contributor

Choose a reason for hiding this comment

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

I.e., can you elaborate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See the example in the comment. The old check does strict type equality (labels included) rather than element-by-element equality (labels excluded)

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you show me what the SIL looks like?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

(I can't really say anything about SIL verification without seeing the SIL).

If you had said that sometimes you pass the payload boxed to the enum, I would have understood you immediately.

I would say the check should be that it is either the payload type or a boxed payload type.

Copy link
Contributor

Choose a reason for hiding this comment

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

(i.e. we had a language issue = p).

ERROR(enum_element_empty_arglist,none,
"empty enum element argument list must be spelled with 'Void'", ())
WARNING(enum_element_empty_arglist_swift3,none,
"empty enum element argument list must be spelled with 'Void'", ())
Copy link
Contributor Author

@CodaFi CodaFi Oct 12, 2017

Choose a reason for hiding this comment

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

This needs phrasing as a warning

@@ -1529,7 +1529,7 @@ func genfoo<T1, T2>(x ix: T1, y iy: T2) where T1 : Prot, T2 : cake.C1, T1.Elemen
key.entities: [
{
key.kind: source.lang.swift.decl.enumelement,
key.name: "case1",
key.name: "case1()",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@benlangmuir Any idea what is causing SourceKit to serialize a null parameter list like this?

Copy link
Contributor

Choose a reason for hiding this comment

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

SourceKit is just calling ValueDecl::getFullName. This test is loading the decl from a Swift module though, so maybe check that?

@CodaFi CodaFi force-pushed the the-pitter-pattern-of-tiny-feet branch from fd94ef2 to 59447ec Compare October 12, 2017 23:46
@CodaFi CodaFi force-pushed the the-pitter-pattern-of-tiny-feet branch 2 times, most recently from 3180456 to e1e61e6 Compare January 7, 2018 01:20
@CodaFi
Copy link
Contributor Author

CodaFi commented Jan 7, 2018

@slavapestov I'm going to try to make everything go through applyNormalCall once the tests pass.

@CodaFi CodaFi force-pushed the the-pitter-pattern-of-tiny-feet branch from e1e61e6 to f3db926 Compare January 7, 2018 03:59
@CodaFi
Copy link
Contributor Author

CodaFi commented Jan 7, 2018

@swift-ci please smoke test

@DevAndArtist
Copy link
Contributor

@CodaFi Any progress to this PR? I'm really looking forward to this feature. :)

@CodaFi CodaFi force-pushed the the-pitter-pattern-of-tiny-feet branch from f3db926 to 85ce4fc Compare February 27, 2018 19:36
@CodaFi
Copy link
Contributor Author

CodaFi commented Feb 27, 2018

Got a pile of test failures with this patch. Turns out changing SILGen changes SILGen

    Swift(macosx-x86_64) :: IRGen/enum_resilience.swift
    Swift(macosx-x86_64) :: SILGen/argument_shuffle_swift3.swift
    Swift(macosx-x86_64) :: SILGen/default_arguments.swift
    Swift(macosx-x86_64) :: SILGen/enum.swift
    Swift(macosx-x86_64) :: SILGen/errors.swift
    Swift(macosx-x86_64) :: SILGen/indirect_enum.swift
    Swift(macosx-x86_64) :: SILGen/opaque_values_silgen.swift
    Swift(macosx-x86_64) :: SILGen/toplevel_errors.swift
    Swift(macosx-x86_64) :: SILGen/tuples.swift
    Swift(macosx-x86_64) :: SILOptimizer/access_marker_verify.swift
    Swift(macosx-x86_64) :: SILOptimizer/definite-init-wrongscope.swift

@rudkx rudkx self-requested a review February 27, 2018 20:43
@dduan
Copy link
Contributor

dduan commented Mar 2, 2018

I've rebased this PR last weekend: https://github.com/dduan/swift/tree/the-pitter-pattern-of-tiny-feet

@CodaFi CodaFi force-pushed the the-pitter-pattern-of-tiny-feet branch from 85ce4fc to b0e9362 Compare March 18, 2018 04:41
@CodaFi
Copy link
Contributor Author

CodaFi commented Mar 18, 2018

In theory this passes the tests now

@swift-ci please smoke test

@CodaFi CodaFi force-pushed the the-pitter-pattern-of-tiny-feet branch from b0e9362 to 2373191 Compare March 19, 2018 02:09
@CodaFi
Copy link
Contributor Author

CodaFi commented Mar 19, 2018

@slavapestov I think a combination of my removing the applyEnumElementConstructor path and your work on SILGen for nil is causing malformed code to be emitted after you apply this patch:

SILGen/objc_blocks_bridging.swift

SIL verification failed: instruction isn't dominated by its operand: Dominance->properlyDominates(valueI, I)
Verifying instruction:
%35 = partial_apply [callee_guaranteed] %34(%33) : $@convention(thin) (@NoEscape @callee_guaranteed (@in ()) -> @out ()) -> () // users: %60, %36
-> destroy_value %35 : $@callee_guaranteed () -> () // id: %60

@CodaFi
Copy link
Contributor Author

CodaFi commented Mar 22, 2018

Closed for #15418

@CodaFi CodaFi closed this Mar 22, 2018
@CodaFi CodaFi deleted the the-pitter-pattern-of-tiny-feet branch December 22, 2019 02:59
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.

5 participants