modularml / mojo

The Mojo Programming Language
https://docs.modular.com/mojo/manual/
Other
23.24k stars 2.6k forks source link

[BUG] Can't get number of cores at compile time #3683

Open helehex opened 2 weeks ago

helehex commented 2 weeks ago

Bug description

This happens for sys.info.num_physical_cores(), sys.info.num_logical_cores() and sys.info.num_performance_cores.

Steps to reproduce

from sys.info import num_physical_cores

fn main():
    alias cores = num_physical_cores()
    print(cores)

System information

Host Information
  ================

  Target Triple: x86_64-unknown-linux
  CPU: skylake
  CPU Features: adx, aes, avx, avx2, bmi, bmi2, clflushopt, cmov, crc32, cx16, cx8, f16c, fma, fsgsbase, fxsr, invpcid, lzcnt, mmx, movbe, pclmul, popcnt, prfchw, rdrnd, rdseed, sahf, sgx, sse, sse2, sse3, sse4.1, sse4.2, ssse3, x87, xsave, xsavec, xsaveopt, xsaves

mojo 2024.10.1619 (829ffb25)
JoeLoser commented 2 weeks ago

This is because they're implemented backed by C++ via an external_call function. Currently, the compile-time interpreter can't see through the external_call.

helehex commented 2 weeks ago

Ah ok.