lean4-htt/src/library
Mac Malone 5bb9839887
fix: symbol clashes between packages (#11082)
This PR prevents symbol clashes between (non-`@[export]`) definitions
from different Lean packages.

Previously, if two modules define a function with the same name and were
transitively imported (even privately) by some downstream module,
linking would fail due to a symbol clash. Similarly, if a user defined a
symbol with the same name as one in the `Lean` library, Lean would use
the core symbol even if one did not import `Lean`.

This is solved by changing Lean's name mangling algorithm to include an
optional package identifier. This identifier is provided by Lake via
`--setup` when building a module. This information is weaved through the
elaborator, interpreter, and compiler via a persistent environment
extension that associates modules with their package identifier.

With a package identifier, standard symbols have the form
`lp_<pkg-id>_<mangled-def>`. Without one, the old scheme is used (i.e.,
`l_<mangled-def>`). Module initializers are also prefixed with package
identifier (if any). For example, the initializer for a module `Foo` in
a package `test` is now `initialize_test_Foo` (instead of
`initialize_Foo`). Lake's default for native library names has also been
adjusted accordingly, so that libraries can still, by default, be used
as plugins. Thus, the default library name of the `lean_lib Foo` in
`package test` will now be `libtest_Foo`.

When using Lake to build the Lean core (i.e., `bootstrap = true`), no
package identifier will be used. Thus, definitions in user packages can
never have symbol clashes with core.

Closes #222.
2025-11-19 02:24:44 +00:00
..
constructions refactor: reimplement mkNoConfusionType in Lean (#10334) 2025-09-11 07:56:59 +00:00
annotation.cpp
annotation.h
aux_recursors.cpp
aux_recursors.h
bin_app.cpp
bin_app.h
class.cpp
class.h
CMakeLists.txt chore: move llvm.cpp from library/compiler to library (#9270) 2025-07-09 02:13:08 +00:00
constants.cpp
constants.h
constants.txt
dynlib.cpp feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
dynlib.h
elab_environment.cpp chore: remove unnecessary include of ir_interpreter.h (#9262) 2025-07-08 18:09:20 +00:00
elab_environment.h perf: mark move constructors and assignment operators as noexcept (#10784) 2025-10-22 14:21:51 +00:00
expr_lt.cpp feat: add the nondep field of Expr.letE to the C++ data model (#8751) 2025-06-14 23:10:27 +00:00
expr_lt.h
expr_pair.h
expr_pair_maps.h
expr_unsigned_map.h
formatter.cpp
formatter.h
init_attribute.cpp chore: move the IR interpreter from library/compiler to library (#9265) 2025-07-08 20:45:55 +00:00
init_attribute.h chore: move the IR interpreter from library/compiler to library (#9265) 2025-07-08 20:45:55 +00:00
init_module.cpp chore: move the IR interpreter from library/compiler to library (#9265) 2025-07-08 20:45:55 +00:00
init_module.h
ir_interpreter.cpp fix: symbol clashes between packages (#11082) 2025-11-19 02:24:44 +00:00
ir_interpreter.h chore: move the IR interpreter from library/compiler to library (#9265) 2025-07-08 20:45:55 +00:00
ir_types.h feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
llvm.cpp feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
max_sharing.cpp
max_sharing.h
module.cpp
module.h
num.cpp
num.h
print.cpp feat: add the nondep field of Expr.letE to the C++ data model (#8751) 2025-06-14 23:10:27 +00:00
print.h
profiling.cpp
profiling.h
projection.cpp
projection.h perf: mark move constructors and assignment operators as noexcept (#10784) 2025-10-22 14:21:51 +00:00
reducible.cpp
reducible.h
replace_visitor.cpp
replace_visitor.h
suffixes.h fix: allow arbitrary sorts in structural recursion over reflexive inductive types (#7639) 2025-06-13 21:51:09 +00:00
time_task.cpp feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
time_task.h
util.cpp refactor: remove unnecessary export attributes (#9281) 2025-07-09 16:55:00 +00:00
util.h refactor: remove unnecessary export attributes (#9281) 2025-07-09 16:55:00 +00:00