Skip to content

Hoist CFGState and BBState out of function scope #19510

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

Merged
merged 1 commit into from
Oct 25, 2018

Conversation

gmittert
Copy link
Contributor

MSVC (Version 19.15.26726) has some really wonky behaviour with enums and
structs in function scopes. Hoisting them outside seems to work around
it.

Here's the error message, I don't at all understand why it would cause this specific error.

C:\PROGRA~2\MIB055~1\2017\PROFES~1\VC\Tools\MSVC\1415~1.267\bin\Hostx64\x64\cl.exe  /nologo /TP -DCMARK_STATIC_DEFINE -DGTEST_HAS_RTTI=0 -DUNICODE -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_HAS_EXCEPTIONS=0 -D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -D_UNICODE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Ilib\SIL -Iswift\lib\SIL -Iinclude -Iswift\include -Illvm\include -Ibuild\Ninja-DebugAssert\llvm-windows-amd64\include -Ibuild\Ninja-DebugAssert\llvm-windows-amd64\tools\clang\include -Illvm\tools\clang\include -Icmark\src -Ibuild\Ninja-DebugAssert\cmark-windows-amd64\src -I"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.15.26726\\include" -I"C:\Program Files (x86)\Windows Kits\10\\Include\10.0.17134.0\ucrt" -I"C:\Program Files (x86)\Windows Kits\10\\Include\10.0.17134.0\shared" -I"C:\Program Files (x86)\Windows Kits\10\\Include\10.0.17134.0\um" /DWIN32 /D_WINDOWS   /Zc:inline /Zc:strictStrings /Oi /Zc:rvalueCast /W4 -wd4141 -wd4146 -wd4180 -wd4244 -wd4258 -wd4267 -wd4291 -wd4345 -wd4351 -wd4355 -wd4456 -wd4457 -wd4458 -wd4459 -wd4503 -wd4624 -wd4722 -wd4800 -wd4100 -wd4127 -wd4512 -wd4505 -wd4610 -wd4510 -wd4702 -wd4245 -wd4706 -wd4310 -wd4701 -wd4703 -wd4389 -wd4611 -wd4805 -wd4204 -wd4577 -wd4091 -wd4592 -wd4319 -wd4324 -w14062 -we4238 /we4062 /wd4068 -DOBJC_OLD_DISPATCH_PROTOTYPES=0 /MDd /Zi /Ob0 /Od /RTC1    /EHs-c- /GR- /Od -DLLVM_ON_WIN32 -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_USE_WINAPI_FAMILY_DESKTOP_APP -D_DLL -D_ENABLE_ATOMIC_ALIGNMENT_FIX -D_HAS_STATIC_RTTI=0 -UNDEBUG -std:c++14 /Folib\SIL\CMakeFiles\swiftSIL.dir\SILVerifier.cpp.obj /Fdlib\SIL\CMakeFiles\swiftSIL.dir\swiftSIL.pdb /FS -c swift\lib\SIL\SILVerifier.cpp
swift\lib\SIL\SILVerifier.cpp(4831): error C2888: 'void swift::SILFunction::verify(bool) const': symbol cannot be defined within namespace 'std'
swift\lib\SIL\SILVerifier.cpp(4842): error C2888: 'void swift::SILFunction::verifyCriticalEdges(void) const': symbol cannot be defined within namespace 'std'
swift\lib\SIL\SILVerifier.cpp(4851): error C2888: 'void swift::SILProperty::verify(const swift::SILModule &) const': symbol cannot be defined within namespace 'std'
swift\lib\SIL\SILVerifier.cpp(4906): error C2888: 'void swift::SILVTable::verify(const swift::SILModule &) const': symbol cannot be defined within namespace 'std'
swift\lib\SIL\SILVerifier.cpp(4963): error C2888: 'void swift::SILWitnessTable::verify(const swift::SILModule &) const': symbol cannot be defined within namespace 'std'
swift\lib\SIL\SILVerifier.cpp(5003): error C2888: 'void swift::SILDefaultWitnessTable::verify(const swift::SILModule &) const': symbol cannot be defined within namespace 'std'
swift\lib\SIL\SILVerifier.cpp(5033): error C2888: 'void swift::SILGlobalVariable::verify(void) const': symbol cannot be defined within namespace 'std'
swift\lib\SIL\SILVerifier.cpp(5058): error C2888: 'void swift::SILModule::verify(void) const': symbol cannot be defined within namespace 'std'
swift\lib\SIL\SILVerifier.cpp(5149): error C2888: 'bool swift::maybeScopeless(swift::SILInstruction &)': symbol cannot be defined within namespace 'std'

Very oddly, commenting out all the insertResult.first->second lines (Lines 4536, 4543, 4565) also makes the error message go away.

I also see the error in #19303, but since hoisting out BBState is what fixed it, I also had to hoist out CFGState as in that PR.

Also, with this change, Swift successfully now compiles and links (but immediately crashes when run) on Windows building with MSVC on my machine.

Copy link
Contributor

@gottesmm gottesmm left a comment

Choose a reason for hiding this comment

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

This looks simple enough. I am slightly worried about infecting the struct level namespace here with these constructs. Maybe instead construct a subtype in there that verifies the flow sensitive rules instead?

@gmittert
Copy link
Contributor Author

I've now nested the enum in the struct, that way Normal/YieldOnceResumed/YieldUnwind don't get dumped into the namespace.

@compnerd
Copy link
Member

compnerd commented Oct 4, 2018

@swift-ci please test

MSVC (Version 19.15.26726) has some really wonky behaviour with enums and
structs in function scopes. Hoisting them outside seems to work around
it.
@compnerd
Copy link
Member

@swift-ci please test

1 similar comment
@lanza
Copy link
Contributor

lanza commented Oct 23, 2018

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - c71d24b

@lanza
Copy link
Contributor

lanza commented Oct 24, 2018

@swift-ci please test Linux Platform

@lanza
Copy link
Contributor

lanza commented Oct 24, 2018

@compnerd Is this approved?

Copy link
Contributor

@gottesmm gottesmm left a comment

Choose a reason for hiding this comment

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

LGTM

@lanza lanza merged commit fcd2b97 into swiftlang:master Oct 25, 2018
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