nrn icon indicating copy to clipboard operation
nrn copied to clipboard

Prevent user from declaring variables and functions with same name

Open pramodk opened this issue 3 years ago • 4 comments

  • Today user can "declare" a variable in the NEURON block and then PROCEDURE or FUNCTION with the same name. For example, the below doesn't raise any error today:

    NEURON {
        SUFFIX glia
        RANGE alfa
    }
    
    FUNCTION alfa(v(mV)) {
        alfa = exp(v)
    }
    
  • The reason this works is that the RANGE alfa declaration in the NEURON block is not complete (i.e. variable needs to be "defined" in blocks like ASSIGNED, PARAMETER, etc) and hence doesn't appear anywhere in the generated code. If we try to use alfa as a variable then that is a warning and resulted in a compilation error.

  • This behavior kind of works but is error-prone. Apart from corner cases and confusing behavior, it's difficult to do certain analyses that we would like to do (e.g. in new NMODL code generation).

  • So for robustness and simplicity, we now throw an error if a user tries to declare a variable and function with the same name.

        $ ./bin/nocmodl mod_x/test.mod Translating mod_x/test.mod into mod_x/test.cpp
            Error: alfa used as both variable and function in file mod/test.mod 
    
  • [ ] Once there is a wheel, I will launch ModelDB CI to check if any MOD files need to be fixed
  • [x] A PR to dbbs-lab/dbbs-mod-collection would be nice! dbbs-lab/dbbs-mod-collection/pull/7
  • [x] Update dentate model soltesz-lab/dentate/pull/4
  • [x] Update tests like testcorenrn and reduced_dentate

pramodk avatar Sep 23 '22 12:09 pramodk

✔️ 7c4660bc5911dfa38cff1372ea2229db04274a3f -> Azure artifacts URL

azure-pipelines[bot] avatar Sep 23 '22 12:09 azure-pipelines[bot]

Codecov Report

Merging #1992 (f0fe629) into master (d2564ff) will increase coverage by 0.00%. The diff coverage is 76.92%.

@@           Coverage Diff           @@
##           master    #1992   +/-   ##
=======================================
  Coverage   46.48%   46.48%           
=======================================
  Files         527      527           
  Lines      119181   119191   +10     
=======================================
+ Hits        55402    55410    +8     
- Misses      63779    63781    +2     
Impacted Files Coverage Δ
src/nmodl/io.cpp 65.06% <0.00%> (ø)
src/nmodl/nocpout.cpp 93.25% <ø> (ø)
src/nmodl/consist.cpp 79.59% <83.33%> (+0.10%) :arrow_up:

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

codecov-commenter avatar Sep 23 '22 14:09 codecov-commenter

✔️ f0fe629fa233d4a9eeacac74fe7e270bc53b4420 -> Azure artifacts URL

azure-pipelines[bot] avatar Sep 23 '22 14:09 azure-pipelines[bot]

ModelDB models / mod files that needs to be fixed are:

➜  nrn-modeldb-ci git:(master) ✗ grep "both variable and function in file" log
Error: new_seed used as both variable and function in file ./cache/138205/Schizophr/Gfluct.mod
Error: new_seed used as both variable and function in file ./cache/155601/ProdduturEtAl2013/Gfluct2.mod
Error: new_seed used as both variable and function in file ./cache/190559/MiglioreEJN2016/Gfluct.mod
Error: minf used as both variable and function in file ./cache/139657/Kopp-Scheinpflug2011/lva.mod
Error: new_seed used as both variable and function in file ./cache/139657/Kopp-Scheinpflug2011/mhh_Gfluct.mod
Error: new_seed used as both variable and function in file ./cache/124513/dentate_gyrus/Gfluct2.mod
Error: new_seed used as both variable and function in file ./cache/262115/demo_destexhe-pare-1999/corrgen8.mod
Error: r used as both variable and function in file ./cache/139656/network/Golgi_hcn1.mod
Error: alfa used as both variable and function in file ./cache/139656/network/GRC_NA.mod
Error: diffusione used as both variable and function in file ./cache/116835/GrC/GRC_GABA.mod
Error: alfa used as both variable and function in file ./cache/116835/GrC/GRC_NA.mod
Error: new_seed used as both variable and function in file ./cache/232876/TCR/high_conductance_state/Gfluct.mod
Error: new_seed used as both variable and function in file ./cache/240116/modeldb-bulb3d/sim/Gfluct.mod
Error: new_seed used as both variable and function in file ./cache/217882/LombardoHarrington2016/Gfluctdv.mod
Error: curr used as both variable and function in file ./cache/151825/Demo/epsp.mod
Error: new_seed used as both variable and function in file ./cache/97917/splitcell/pardentategyrus/Gfluct2.mod
Error: new_seed used as both variable and function in file ./cache/183949/Discharge_hysteresis/Gfluctdv.mod
Error: new_seed used as both variable and function in file ./cache/155602/YuEtAl2013/Gfluct2.mod
Error: r used as both variable and function in file ./cache/127021/Golgi_cell_NaKATPAse/Golgi_hcn1.mod
Error: new_seed used as both variable and function in file ./cache/143671/PowersEtAl2012/code/Gfluctdv.mod
Error: new_seed used as both variable and function in file ./cache/144482/Pyramidal_STDP_Gomez_Delgado_2010/mechanism/mechanism_cell1/Gfluct.mod
Error: minf used as both variable and function in file ./cache/53893/ca_t_lva/lva.mod
Error: alfa used as both variable and function in file ./cache/265584/Granule_cell_2020/04_GrC_2020_accelerating/mod_files/GRC_NA_FHF.mod
Error: alfa used as both variable and function in file ./cache/265584/Granule_cell_2020/04_GrC_2020_accelerating/mod_files/GRC_NA.mod
Error: alfa used as both variable and function in file ./cache/265584/Granule_cell_2020/02_GrC_2020_mild_adapting/mod_files/GRC_NA_FHF.mod
Error: alfa used as both variable and function in file ./cache/265584/Granule_cell_2020/02_GrC_2020_mild_adapting/mod_files/GRC_NA.mod
Error: alfa used as both variable and function in file ./cache/265584/Granule_cell_2020/03_GrC_2020_adapting/mod_files/GRC_NA_FHF.mod
Error: alfa used as both variable and function in file ./cache/265584/Granule_cell_2020/03_GrC_2020_adapting/mod_files/GRC_NA.mod
Error: alfa used as both variable and function in file ./cache/265584/Granule_cell_2020/01_GrC_2020_regular/mod_files/GRC_NA_FHF.mod
Error: alfa used as both variable and function in file ./cache/265584/Granule_cell_2020/01_GrC_2020_regular/mod_files/GRC_NA.mod
Error: r used as both variable and function in file ./cache/232023/cerebellar_granular_network/mechanisms/Golgi_CL/Golgi_hcn1.mod
Error: new_seed used as both variable and function in file ./cache/150024/CNModel_May2013/Ifluct8.mod
Error: new_seed used as both variable and function in file ./cache/122329/GPSingleCompartment/syn.mod
Error: new_seed used as both variable and function in file ./cache/141273/Vierling-ClaassenEtAl2010/Gfluct.mod
Error: new_seed used as both variable and function in file ./cache/83590/Arsiero_et_al2007/mechanisms/Ifluct1.mod

pramodk avatar Sep 23 '22 14:09 pramodk

As PRs to respective ModelDB models are created, I will merge this.

pramodk avatar Sep 24 '22 10:09 pramodk