[swift-dev] Problem in parsing SIL

Mikio Takeuchi mikio.takeuchi at gmail.com
Wed Jun 22 09:43:17 CDT 2016


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 at swift.org>:

>
> > On Jun 21, 2016, at 14:10, Joe Groff via swift-dev <swift-dev at swift.org>
> wrote:
> >
> >
> >> On Jun 21, 2016, at 2:03 PM, Slava Pestov via swift-dev <
> swift-dev at 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 at swift.org
> https://lists.swift.org/mailman/listinfo/swift-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20160622/248982c8/attachment.html>


More information about the swift-dev mailing list