> On Dec 10, 2015, at 8:31 AM, Joe Groff <jgr...@apple.com> wrote: > >> >> On Dec 9, 2015, at 4:15 PM, Adrian Prantl via swift-dev >> <swift-dev@swift.org> wrote: >> >> In order to write textual SIL -> SIL testcases that exercise the handling of >> debug information by SIL passes, we need to make a couple of additions to >> the textual SIL language. In memory, the debug information attached to SIL >> instructions references information from the AST. If we want to create debug >> info from parsing a textual .sil file, these bits need to be made explicit. >> >> Let me illustrate this with an example. The function >> >>> func foo(x : Int) -> Int { >>> return bar(x) >>> } >> >> is compiled to SIL as >> >>> // main.foo (Swift.Int) -> Swift.Int >>> sil hidden @_TF4main3fooFSiSi : $@convention(thin) (Int) -> Int { >>> // %0 // users: %1, %2, %4 >>> bb0(%0 : $Int): >>> debug_value %0 : $Int // let x, argno: 1 // id: %1 >>> line:1:10:in_prologue >>> return %4 : $Int // id: %5 line:2:3:return >>> } >> >> Note that there is a bunch of information available in comments that will be >> lost once we parse that textual SIL again. I’d like to add syntax to SIL for >> the information in the comments. This proposal deals with lifting the debug >> variable information (the first comment) into actual SIL syntax. A similar >> proposal for locations will be coming soon. >> With the proposed syntax, this could like like: >> >>> sil hidden @_TF4main3fooFSiSi : $@convention(thin) (Int) -> Int { >>> bb0(%0 : $Int): >>> debug_value %0 : $Int, !dbg_var(name: "x", type: "_TTSi", argno: 1) >>> return %4 : $Int >>> } >> >> More formally, debug variable info may be attached to debug_value, >> debug_value_addr, alloc_box, and alloc_stack instructions. >> >> sil-instruction ::= 'alloc_stack' sil-type dbg-var >> sil-instruction ::= 'alloc_stack' sil-type dbg-var >> sil-instruction ::= debug_value sil-operand dbg-var >> sil-instruction ::= debug_value_addr sil-operand dbg-var >> dbg-var ::= ‘!dbg_var’ ‘(‘ var-attr (',' var-attr)*) ‘)' >> var-attr ::= ‘name:’ string-literal >> var-attr ::= ’type:’ string-literal >> var-attr ::= ‘argno:’ integer-literal >> >> This syntax for `dbg-var` is borrowed straight from LLVM IR and thus invokes >> a familiar feeling. Since the primary use-case of it will be in test cases, >> the verbose dictionary-like syntax is really helpful. >> >> Syntax alternatives I’ve considered and rejected include: >> 1. debug_value %0 : $Int, “x”, “_TtSi”, 1 >> Why: Hard to read, potentially ambiguous because some fields are optional. >> >> 2. debug_value [name “x”] [type “_TtSi”] [argno 1] %0 : $Int >> Why: Attributes in square brackets don’t typically have arguments and come >> before the entity they are modifying. >> >> 3. debug_value @var(name: “x”, type: “_TtSi”, argno: 1) %0 : $Int >> Why: The ‘@‘ sigil is used not just for attributes but also for global >> symbols and thus creates an ambiguity. > > Thanks for working on this, Adrian! My thoughts: > > - I don't see a reason to mangle the type name at SIL time. You should > reference the formal AST type directly in the instruction, and print and > parse it using the normal (Swift) type parser.
Good point. Is it safe to assume that all types representable in textual SIL? I’m slightly worried that a SIL pass might introduce a type (e.g., a generic function specialization) for which we don’t have any Swift syntax. Thinking about it though — even if there is no syntax, we would probably want to create one, so the type can be used in the debugger and REPL. > - Since these are core parts of the instruction, I would say they need no > decoration at all; they should just be part of the instruction syntax: > > debug_value %0 : $Int, name "x", type $Int, argno 1 > sil-instruction ::= 'alloc_stack' sil-type (‘,' debugvar-attr)* sil-instruction ::= 'alloc_stack' sil-type (‘,’ debugvar-attr)* sil-instruction ::= debug_value sil-operand (‘,' debugvar-attr)* sil-instruction ::= debug_value_addr sil-operand (‘,' debugvar-attr)* debugvar-attr ::= ‘name’ string-literal debugvar-attr ::= ’type’ type // only needed where AST type ≠ SIL type debugvar-attr ::= ‘argno’ integer-literal Works for me. Thanks for the feedback, Adrian _______________________________________________ swift-dev mailing list swift-dev@swift.org https://lists.swift.org/mailman/listinfo/swift-dev