Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix duplicate declaration of conductance variable g #929

Merged
merged 3 commits into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/codegen/codegen_c_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -857,11 +857,20 @@ std::vector<SymbolType> CodegenCVisitor::get_float_variables() {
if (info.vectorize) {
variables.push_back(make_symbol(naming::VOLTAGE_UNUSED_VARIABLE));
}

if (breakpoint_exist()) {
std::string name = info.vectorize ? naming::CONDUCTANCE_UNUSED_VARIABLE
: naming::CONDUCTANCE_VARIABLE;
variables.push_back(make_symbol(name));

// make sure conductance variable like `g` is not already defined
if (auto r = std::find_if(variables.cbegin(),
variables.cend(),
[&](const auto& s) { return name == s->get_name(); });
r == variables.cend()) {
variables.push_back(make_symbol(name));
}
}

if (net_receive_exist()) {
variables.push_back(make_symbol(naming::T_SAVE_VARIABLE));
}
Expand Down Expand Up @@ -4582,6 +4591,9 @@ void CodegenCVisitor::print_data_structures(bool print_initialisers) {
}

void CodegenCVisitor::print_v_unused() const {
if (!info.vectorize) {
return;
}
printer->add_line("#if NRN_PRCELLSTATE");
printer->add_line("inst->v_unused[id] = v;");
printer->add_line("#endif");
Expand Down
28 changes: 17 additions & 11 deletions test/unit/codegen/codegen_c_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,16 @@ SCENARIO("Check instance variable definition order", "[codegen][var_order]") {
// In the below mod file, ion variables ncai and lcai are declared
// as state variables as well as range variables. The issue about
// this mod file ordering was fixed in #443.
// We also use example from #888 where mod file declared `g` as a
// conductance variable in a non-threadsafe mod file and resulting
// into duplicate definition of `g` in the instance structure.
GIVEN("ccanl.mod: mod file from reduced_dentate model") {
std::string nmodl_text = R"(
NEURON {
SUFFIX ccanl
USEION nca READ ncai, inca, enca WRITE enca, ncai VALENCE 2
USEION lca READ lcai, ilca, elca WRITE elca, lcai VALENCE 2
RANGE caiinf, catau, cai, ncai, lcai, eca, elca, enca
RANGE caiinf, catau, cai, ncai, lcai, eca, elca, enca, g
}
UNITS {
FARADAY = 96520(coul)
Expand All @@ -207,11 +210,14 @@ SCENARIO("Check instance variable definition order", "[codegen][var_order]") {
enca(mV)
elca(mV)
eca(mV)
g(S/cm2)
}
STATE {
ncai(mM)
lcai(mM)
}
BREAKPOINT {}
DISCRETE seq {}
)";

THEN("Ion variables are defined in the order of USEION") {
Expand All @@ -229,16 +235,16 @@ SCENARIO("Check instance variable definition order", "[codegen][var_order]") {
inst->caiinf = ml->data+1*pnodecount;
inst->cai = ml->data+2*pnodecount;
inst->eca = ml->data+3*pnodecount;
inst->ica = ml->data+4*pnodecount;
inst->inca = ml->data+5*pnodecount;
inst->ilca = ml->data+6*pnodecount;
inst->enca = ml->data+7*pnodecount;
inst->elca = ml->data+8*pnodecount;
inst->ncai = ml->data+9*pnodecount;
inst->Dncai = ml->data+10*pnodecount;
inst->lcai = ml->data+11*pnodecount;
inst->Dlcai = ml->data+12*pnodecount;
inst->v_unused = ml->data+13*pnodecount;
inst->g = ml->data+4*pnodecount;
inst->ica = ml->data+5*pnodecount;
inst->inca = ml->data+6*pnodecount;
inst->ilca = ml->data+7*pnodecount;
inst->enca = ml->data+8*pnodecount;
inst->elca = ml->data+9*pnodecount;
inst->ncai = ml->data+10*pnodecount;
inst->Dncai = ml->data+11*pnodecount;
inst->lcai = ml->data+12*pnodecount;
inst->Dlcai = ml->data+13*pnodecount;
inst->ion_ncai = nt->_data;
inst->ion_inca = nt->_data;
inst->ion_enca = nt->_data;
Expand Down