Problem in parsing SIL

Hi,

I am learning SIL and trying to compile SIL generated by the Swift compiler.
I succeeded in doing so with a simple Swift program for just printing "hi",
but I got errors with another simple program which includes a declaration
of a trivial class.

I am running swift-3.0-preview-1 bundled with Xcode8-beta on OS X El
Capitan.

$ uname -a
Darwin localhost 15.5.0 Darwin Kernel Version 15.5.0: Tue Apr 19 18:36:36
PDT 2016; root:xnu-3248.50.21~8/RELEASE_X86_64 x86_64
$ swiftc --version
Apple Swift version 3.0 (swiftlang-800.0.30 clang-800.0.24)
Target: x86_64-apple-macosx10.9
$ cat print.swift
print("hi")
$ swiftc -emit-silgen print.swift > print.sil
$ swiftc -parse-sil print.sil
$ ./print
hi
$ cat classdecl.swift
class MyObject { }
$ swiftc -emit-silgen classdecl.swift > classdecl.sil
$ swiftc -parse-sil classdecl.sil
classdecl.sil:26:105: error: use of undeclared type 'MyObject'
sil_scope 2 { loc "classdecl.swift":1:7 parent @_TFC9classdecl8MyObjectD :
$@convention(method) (@owned MyObject) -> () }

^~~~~~~~
classdecl.sil:26:121: error: extraneous '}' at top level
sil_scope 2 { loc "classdecl.swift":1:7 parent @_TFC9classdecl8MyObjectD :
$@convention(method) (@owned MyObject) -> () }

^

(omitted)

If anybody know any clue, please let me know.

Thanks,
Mikio Takeuchi

Hi Mikio,

Try this:

swiftc -frontend -emit-silgen classdecl.swift > classdecl.sil
swiftc -parse-sil classdecl.sil

I'm not sure why -emit-silgen sometimes emits type declarations and other times not. The only difference I can see is what without the -frontend flag, the driver passes in -primary-file, whereas with -frontend, it does not.

Perhaps Joe or Jordan can chime in.

···

On Jun 14, 2016, at 2:39 AM, Mikio Takeuchi via swift-dev <swift-dev@swift.org> wrote:

Hi,

I am learning SIL and trying to compile SIL generated by the Swift compiler.
I succeeded in doing so with a simple Swift program for just printing "hi",
but I got errors with another simple program which includes a declaration of a trivial class.

I am running swift-3.0-preview-1 bundled with Xcode8-beta on OS X El Capitan.

$ uname -a
Darwin localhost 15.5.0 Darwin Kernel Version 15.5.0: Tue Apr 19 18:36:36 PDT 2016; root:xnu-3248.50.21~8/RELEASE_X86_64 x86_64
$ swiftc --version
Apple Swift version 3.0 (swiftlang-800.0.30 clang-800.0.24)
Target: x86_64-apple-macosx10.9
$ cat print.swift
print("hi")
$ swiftc -emit-silgen print.swift > print.sil
$ swiftc -parse-sil print.sil
$ ./print
hi
$ cat classdecl.swift
class MyObject { }
$ swiftc -emit-silgen classdecl.swift > classdecl.sil
$ swiftc -parse-sil classdecl.sil
classdecl.sil:26:105: error: use of undeclared type 'MyObject'
sil_scope 2 { loc "classdecl.swift":1:7 parent @_TFC9classdecl8MyObjectD : $@convention(method) (@owned MyObject) -> () }
                                                                                                        ^~~~~~~~
classdecl.sil:26:121: error: extraneous '}' at top level
sil_scope 2 { loc "classdecl.swift":1:7 parent @_TFC9classdecl8MyObjectD : $@convention(method) (@owned MyObject) -> () }
                                                                                                                        ^

(omitted)

If anybody know any clue, please let me know.

Thanks,
Mikio Takeuchi
_______________________________________________
swift-dev mailing list
swift-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-dev

This is clearly a bug, but SIL's parser and printer quality generally doesn't have much pressure on it beyond what's minimally necessary to enable optimizer and codegen debugging.

-Joe

···

On Jun 21, 2016, at 2:03 PM, Slava Pestov via swift-dev <swift-dev@swift.org> wrote:

Hi Mikio,

Try this:

swiftc -frontend -emit-silgen classdecl.swift > classdecl.sil
swiftc -parse-sil classdecl.sil

I'm not sure why -emit-silgen sometimes emits type declarations and other times not. The only difference I can see is what without the -frontend flag, the driver passes in -primary-file, whereas with -frontend, it does not.

Perhaps Joe or Jordan can chime in.

We don't try to print ASTs when -primary-file is passed because it would mean merging ASTs from different files, which isn't going to be correct in the presence of 'private'.

Jordan

···

On Jun 21, 2016, at 14:10, Joe Groff via swift-dev <swift-dev@swift.org> wrote:

On Jun 21, 2016, at 2:03 PM, Slava Pestov via swift-dev <swift-dev@swift.org> wrote:

Hi Mikio,

Try this:

swiftc -frontend -emit-silgen classdecl.swift > classdecl.sil
swiftc -parse-sil classdecl.sil

I'm not sure why -emit-silgen sometimes emits type declarations and other times not. The only difference I can see is what without the -frontend flag, the driver passes in -primary-file, whereas with -frontend, it does not.

Perhaps Joe or Jordan can chime in.

This is clearly a bug, but SIL's parser and printer quality generally doesn't have much pressure on it beyond what's minimally necessary to enable optimizer and codegen debugging.

Thanks Slava, Joe, and Jordan.

With -frontend flag, I was able to parse classdecl.sil.
However, I still have a problem with another very simple Swift source code
which declares a value initialized with an integer literal.

I am wondering if it is possible to compile some non-trivial Swift code to
SIL and parse the SIL to an executable, we can quickly evaluate our ideas
without serious implementation. I appreciate your comment on the planned
capability and current status of parsing SIL instead of Swift source code.

Thanks,
Mikio Takeuchi

$ cat classdecl.swift
class MyObject { }
$ swiftc -frontend -emit-silgen classdecl.swift > classdecl.sil
$ swiftc -parse-sil classdecl.sil
$ cat const.swift
let sz = 10000
$ swiftc -frontend -emit-silgen const.swift > const.sil
$ swiftc -parse-sil const.sil
Cannot construct Inlined loc from the given location.
UNREACHABLE executed at
/Users/buildnode/jenkins/workspace/oss-swift-package-osx/swift/lib/SIL/SILLocation.cpp:211!
0 swift 0x000000010406d00b
llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 43
1 swift 0x000000010406c256
llvm::sys::RunSignalHandlers() + 70
2 swift 0x000000010406d75f SignalHandler(int) + 383
3 libsystem_platform.dylib 0x00007fff9783352a _sigtramp + 26
4 libsystem_platform.dylib 0x00007fff642aeac5 _sigtramp + 3433543093
5 swift 0x000000010406d4ae abort + 14
6 swift 0x000000010400ce77
llvm::llvm_unreachable_internal(char const*, char const*, unsigned int) +
471
7 swift 0x0000000101953cdb
swift::MandatoryInlinedLocation::getMandatoryInlinedLocation(swift::SILLocation)
+ 315
8 swift 0x00000001016e69ad
swift::SILInliner::inlineFunction(swift::FullApplySite,
llvm::ArrayRef<swift::SILValue>) + 429
9 swift 0x000000010174b4f0
runOnFunctionRecursively(swift::SILFunction*, swift::FullApplySite,
swift::SILOptions::LinkingMode, llvm::DenseSet<swift::SILFunction*,
llvm::DenseMapInfo<swift::SILFunction*> >&,
llvm::ImmutableSet<swift::SILFunction*,
llvm::ImutContainerInfo<swift::SILFunction*> >::Factory&,
llvm::ImmutableSet<swift::SILFunction*,
llvm::ImutContainerInfo<swift::SILFunction*> >,
swift::ClassHierarchyAnalysis*) + 3504
10 swift 0x000000010174a573 (anonymous
namespace)::MandatoryInlining::run() + 419
11 swift 0x000000010170025b
swift::SILPassManager::runModulePass(swift::SILModuleTransform*) + 1067
12 swift 0x0000000101700c63
swift::SILPassManager::runOneIteration() + 1043
13 swift 0x00000001017011d3 swift::SILPassManager::run()
+ 1235
14 swift 0x000000010170a8aa
swift::runSILDiagnosticPasses(swift::SILModule&) + 314
15 swift 0x000000010140793c
performCompile(swift::CompilerInstance&, swift::CompilerInvocation&,
llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*) + 13324
16 swift 0x000000010140329f
swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*,
swift::FrontendObserver*) + 2895
17 swift 0x00000001013c5de0 main + 2448
18 libdyld.dylib 0x00007fff9a1a95ad start + 1
19 libdyld.dylib 0x000000000000000e start + 1709533794
Stack dump:
0. Program arguments:
/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2016-06-20-a.xctoolchain/usr/bin/swift
-frontend -c -primary-file const.sil -target x86_64-apple-macosx10.9
-enable-objc-interop -color-diagnostics -parse-sil -module-name const -o
/var/folders/_p/g_rb2m816p18wr5145r762qm0000gn/T/const-1efc86.o
1. While running SILModuleTransform "Mandatory Inlining".
<unknown>:0: error: unable to execute command: Illegal instruction: 4
<unknown>:0: error: compile command failed due to signal (use -v to see
invocation)
$

···

2016-06-22 6:25 GMT+09:00 Jordan Rose via swift-dev <swift-dev@swift.org>:

> On Jun 21, 2016, at 14:10, Joe Groff via swift-dev <swift-dev@swift.org> > wrote:
>
>
>> On Jun 21, 2016, at 2:03 PM, Slava Pestov via swift-dev < > swift-dev@swift.org> wrote:
>>
>> Hi Mikio,
>>
>> Try this:
>>
>> swiftc -frontend -emit-silgen classdecl.swift > classdecl.sil
>> swiftc -parse-sil classdecl.sil
>>
>> I'm not sure why -emit-silgen sometimes emits type declarations and
other times not. The only difference I can see is what without the
-frontend flag, the driver passes in -primary-file, whereas with -frontend,
it does not.
>>
>> Perhaps Joe or Jordan can chime in.
>
> This is clearly a bug, but SIL's parser and printer quality generally
doesn't have much pressure on it beyond what's minimally necessary to
enable optimizer and codegen debugging.

We don't try to print ASTs when -primary-file is passed because it would
mean merging ASTs from different files, which isn't going to be correct in
the presence of 'private'.

Jordan

_______________________________________________
swift-dev mailing list
swift-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-dev