Step 1Wash the beans and soak them overnight in water to cover.
Step 2The next day, drain the beans and place them in a large saucepan with water to cover generously and 4 cloves of garlic. Bring the beans to a boil, reduce heat and cook, partially covered, until the skins wrinkle, about 1 hour.
Step 3To roast the chiles, hold them with tongs directly above a gas flame, turning until charred on all sides, about 10 minutes, or place them beneath the broiler. When charred, put the chiles in a glass bowl, cover with plastic wrap and let them sit until cool enough to handle, about 10 minutes. Remove and discard the skin, then chop the chiles. Set them aside.
Step 4Mash the remaining 4 cloves of garlic in the salt until dissolved to a paste. Heat the oil in a skillet over medium heat, add the onions and garlic paste and cook until the onions are tender, 8 to 10 minutes. Add the tomatoes and chiles and cook until the tomatoes are softened, about 5 minutes.
Step 5Heat the oven to 350 degrees.
Step 6Remove 1 cup of beans with a little of the cooking liquid and mash thoroughly. Drain the remaining beans, reserving the liquid, and place in a bean pot or deep casserole. Stir in the mashed beans, the onion mixture, beer and 1 cup of the reserved liquid.
Step 7Bake until the beans are very tender, adding the reserved liquid as needed to keep them from drying out. Accompany with separate bowls of chopped onion and cilantro to add as desired.