-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[ARITH] Add optional Z3-backed proving to Analyzer #19667
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
Open
Ubospica
wants to merge
1
commit into
apache:main
Choose a base branch
from
Ubospica:2026-06-03-arith-z3-analyzer
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| if(NOT USE_Z3) | ||
| list(APPEND COMPILER_SRCS src/target/z3/z3_prover_off.cc) | ||
| return() | ||
| endif() | ||
|
|
||
| find_package(Z3 QUIET) | ||
| set(Z3_PYTHON_RESULT 1) | ||
|
|
||
| if(NOT Z3_FOUND) | ||
| find_package(Python3 COMPONENTS Interpreter QUIET) | ||
| if(Python3_EXECUTABLE) | ||
| execute_process( | ||
| COMMAND "${Python3_EXECUTABLE}" -c "import z3; print(z3.__path__[0])" | ||
| OUTPUT_VARIABLE Z3_PYTHON_PACKAGE_DIR | ||
| OUTPUT_STRIP_TRAILING_WHITESPACE | ||
| RESULT_VARIABLE Z3_PYTHON_RESULT | ||
| ) | ||
| endif() | ||
|
|
||
| if(Z3_PYTHON_RESULT EQUAL 0 AND NOT Z3_PYTHON_PACKAGE_DIR STREQUAL "") | ||
| find_path(Z3_INCLUDE_DIR NO_DEFAULT_PATH NAMES z3++.h PATHS "${Z3_PYTHON_PACKAGE_DIR}/include") | ||
| find_library( | ||
| Z3_LIBRARY | ||
| NO_DEFAULT_PATH | ||
| NAMES z3 libz3 | ||
| PATHS "${Z3_PYTHON_PACKAGE_DIR}/bin" "${Z3_PYTHON_PACKAGE_DIR}/lib" | ||
| "${Z3_PYTHON_PACKAGE_DIR}/lib64" | ||
| ) | ||
| endif() | ||
| endif() | ||
|
|
||
| if(TARGET z3::libz3 OR TARGET Z3::libz3) | ||
| if(TARGET z3::libz3) | ||
| set(Z3_TARGET z3::libz3) | ||
| else() | ||
| set(Z3_TARGET Z3::libz3) | ||
| endif() | ||
| get_target_property(Z3_TARGET_INCLUDE_DIRS ${Z3_TARGET} INTERFACE_INCLUDE_DIRECTORIES) | ||
| if(Z3_TARGET_INCLUDE_DIRS) | ||
| include_directories(SYSTEM ${Z3_TARGET_INCLUDE_DIRS}) | ||
| endif() | ||
| list(APPEND TVM_LINKER_LIBS ${Z3_TARGET}) | ||
| elseif(Z3_FOUND OR (Z3_INCLUDE_DIR AND Z3_LIBRARY)) | ||
| if(NOT Z3_INCLUDE_DIR AND Z3_CXX_INCLUDE_DIRS) | ||
| set(Z3_INCLUDE_DIR ${Z3_CXX_INCLUDE_DIRS}) | ||
| endif() | ||
| if(NOT Z3_LIBRARY AND Z3_LIBRARIES) | ||
| set(Z3_LIBRARY ${Z3_LIBRARIES}) | ||
| endif() | ||
| if(NOT Z3_INCLUDE_DIR OR NOT Z3_LIBRARY) | ||
| message(FATAL_ERROR "USE_Z3 is ON, but Z3 include directory or library was not found.") | ||
| endif() | ||
| include_directories(SYSTEM ${Z3_INCLUDE_DIR}) | ||
| list(APPEND TVM_LINKER_LIBS ${Z3_LIBRARY}) | ||
| else() | ||
| message(FATAL_ERROR "USE_Z3 is ON, but Z3 was not found. Install Z3 or PyPI z3-solver.") | ||
| endif() | ||
|
|
||
| list(APPEND COMPILER_SRCS src/target/z3/z3_prover_on.cc) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Z3 fallback isn't exception-safe — Z3 can throw z3::exception and nothing catches it, so it escapes Analyzer::CanProve and breaks the calling pass. A fallback shouldn't turn a failed proof into a crash. it's good to wrap the body of Z3Prover::CanProve in try { ... } catch (const z3::exception&) { return false; }.