leanprover / leanprover/lean4

`argv[0]` is not accessible to Lean

Open
#5,819 0 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P-high
Dominant language
Lean
Stars
9.2k
Forks
990
Avg merge
1d 17h
Merged PRs (30d)
175

Description

Prerequisites

Please put an X between the brackets as you perform the following steps:

Description

The lean def main is passed arg[1] to argv[argc - 1].

This is consistent with the behavior of Haskell's getArgs, but Lean does not provide haskell's getProgName.

IO.appPath is not a substitute for argv[0], as:

  • argv[0] contains the pre-resolved symlinks
  • The caller of exec can override argv[0] arbitrarily.
Context

Zulip thread

Steps to Reproduce
  1. Create a lean binary foo
  2. Run (exec -a secret_name ./lake/build/bin/foo)

Expected behavior: secret_name should either be in the first entry of args, or accessible via some IO API

Actual behavior: secret_name is lost forever:

https://github.com/leanprover/lean4/blob/01d414ac36dc28f3e424dabd36d818873fea655c/src/Lean/Compiler/IR/EmitC.lean#L173-L182

Versions

[Output of #eval Lean.versionString]
[OS version, if not using live.lean-lang.org.]

Additional Information

[Additional information, configuration or data that might be necessary to reproduce the issue]

Impact

Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked EmitC.lean lines 173–182 and reproduce the issue by building the foo binary and running exec -a secret_name ./lake/build/bin/foo. Trace how the command-line arguments reach Lean’s main; done means the caller-supplied argv[0] is preserved in the first argument or exposed through an IO API.

Written by the indexing model from the issue text.

Assessment

Domain
backend-api-design, compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.