Skip to content

remove with_context, with_module, with_block MLIR resource managers#2415

Open
mofeing wants to merge 14 commits intomainfrom
ss/deprecate-with-context-managers
Open

remove with_context, with_module, with_block MLIR resource managers#2415
mofeing wants to merge 14 commits intomainfrom
ss/deprecate-with-context-managers

Conversation

@mofeing
Copy link
Collaborator

@mofeing mofeing commented Feb 11, 2026

closures are problematic... we should use MLIR.IR.@scope instead activation during a certain scope.

(open to change name)

@mofeing mofeing force-pushed the ss/deprecate-with-context-managers branch from 5fd678e to bc33ceb Compare February 11, 2026 09:55
@Pangoraw
Copy link
Collaborator

closures are problematic..

could you elaborate why?

@wsmoses
Copy link
Member

wsmoses commented Feb 11, 2026

so closures capture the state of all variables in scope, which can lead to some very unfortunate bugs when doing memory/gc management, they also add nontrivial overhead and extra harder to debug stackframes.

CConv,
)
end
push!(MLIR.IR.body(mod), wrapfunc)
Copy link
Collaborator

Choose a reason for hiding this comment

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

this line becomes redundant iiuc

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

right, I was trying to not use @scope here because it's only one line, but I changed my mind and forgot to remove it.

deactivate(blk)
end
function with_module(f, mod::Module)
depwarn("`with_module` is deprecated, use `@scope` instead.", :with_module)
Copy link
Member

Choose a reason for hiding this comment

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

Considering this is likely package internal, I think I'd be okay [and semver compliant] to remove without dep, if desired

@mofeing
Copy link
Collaborator Author

mofeing commented Feb 11, 2026

@Pangoraw you can find some more context here JuliaLLVM/LLVM.jl#309

@mofeing mofeing changed the title deprecate with_context, with_module, with_block managers remove with_context, with_module, with_block managers Feb 11, 2026
@mofeing mofeing changed the title remove with_context, with_module, with_block managers remove with_context, with_module, with_block MLIR resource managers Feb 11, 2026
@wsmoses wsmoses force-pushed the ss/deprecate-with-context-managers branch from dd6d3c5 to 0b8ae61 Compare February 13, 2026 12:59
@mofeing
Copy link
Collaborator Author

mofeing commented Feb 13, 2026

@wsmoses this is weird. I can confirm that...

  1. sharding and optimize_comms tests only fail on PJRT, and
  2. no PJRT code was modified here or in refactor MLIR.IR ownership to manual disposal #2365

could it be that some bug was unveiled now?

@wsmoses
Copy link
Member

wsmoses commented Feb 13, 2026

Uhhh that's weird, yeah idk what's up

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.

3 participants