Files
swift-mirror/test/expr/capture/generic_params.swift
John McCall 9bee3cac5a Generalize storage implementations to support generalized accessors.
The storage kind has been replaced with three separate "impl kinds",
one for each of the basic access kinds (read, write, and read/write).
This makes it far easier to mix-and-match implementations of different
accessors, as well as subtleties like implementing both a setter
and an independent read/write operation.

AccessStrategy has become a bit more explicit about how exactly the
access should be implemented.  For example, the accessor-based kinds
now carry the exact accessor intended to be used.  Also, I've shifted
responsibilities slightly between AccessStrategy and AccessSemantics
so that AccessSemantics::Ordinary can be used except in the sorts of
semantic-bypasses that accessor synthesis wants.  This requires
knowing the correct DC of the access when computing the access strategy;
the upshot is that SILGenFunction now needs a DC.

Accessor synthesis has been reworked so that only the declarations are
built immediately; body synthesis can be safely delayed out of the main
decl-checking path.  This caused a large number of ramifications,
especially for lazy properties, and greatly inflated the size of this
patch.  That is... really regrettable.  The impetus for changing this
was necessity: I needed to rework accessor synthesis to end its reliance
on distinctions like Stored vs. StoredWithTrivialAccessors, and those
fixes were exposing serious re-entrancy problems, and fixing that... well.
Breaking the fixes apart at this point would be a serious endeavor.
2018-06-30 05:19:03 -04:00

36 lines
1.5 KiB
Swift

// RUN: %target-swift-frontend -dump-ast %s 2>&1 | %FileCheck %s
func doSomething<T>(_ t: T) {}
// CHECK: func_decl{{.*}}"outerGeneric(t:x:)" <T> interface type='<T> (t: T, x: AnyObject) -> ()'
func outerGeneric<T>(t: T, x: AnyObject) {
// Simple case -- closure captures outer generic parameter
// CHECK: closure_expr type='() -> ()' {{.*}} discriminator=0 captures=(<generic> t<direct>) escaping single-expression
_ = { doSomething(t) }
// Special case -- closure does not capture outer generic parameters
// CHECK: closure_expr type='() -> ()' {{.*}} discriminator=1 captures=(x<direct>) escaping single-expression
_ = { doSomething(x) }
// Special case -- closure captures outer generic parameter, but it does not
// appear as the type of any expression
// CHECK: closure_expr type='() -> ()' {{.*}} discriminator=2 captures=(<generic> x<direct>)
_ = { if x is T {} }
// Nested generic functions always capture outer generic parameters, even if
// they're not mentioned in the function body
// CHECK: func_decl{{.*}}"innerGeneric(u:)" <U> interface type='<T, U> (u: U) -> ()' {{.*}} captures=(<generic> )
func innerGeneric<U>(u: U) {}
// Make sure we look through typealiases
typealias TT = (a: T, b: T)
// FIXME: Losing some type sugar here.
// CHECK: func_decl{{.*}}"localFunction(tt:)" interface type='<T> (tt: (a: T, b: T)) -> ()' {{.*}} captures=(<generic> )
func localFunction(tt: TT) {}
// CHECK: closure_expr type='((a: T, b: T)) -> ()' {{.*}} captures=(<generic> )
let _: (TT) -> () = { _ in }
}